﻿namespace Loef
{
	public abstract class IncludeChainBase
	{
		public IncludeChainBase Next { get; private set; }
		public string NextIncludePath { get; private set; }

		public string Value
		{
			get
			{
				string path = NextIncludePath;
				IncludeChainBase cur = Next;
				while (cur != null)
				{
					if (cur.NextIncludePath != null)
						path += (path == "" ? "" : ".") + cur.NextIncludePath;
					cur = cur.Next;
				}
				return path;
			}
		}


		protected IncludeChainBase()
		{
			NextIncludePath = null;
			Next = null;
		}

		protected T Chain<T>(string path) where T : IncludeChainBase, new()
		{
			Next = new T();
			NextIncludePath = path;
			return (T)Next;
		}

		public override string ToString()
		{
			return Value;
		}

	}
}
